package com.stoken.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.stoken.dao.MemberLeaveMessageDao;
import com.stoken.dao.MemberLeaveReplyDao;
import com.stoken.dao.NoticeDao;
import com.stoken.domain.MemberLeaveMessage;
import com.stoken.domain.MemberLeaveReply;
import com.stoken.domain.Notice;
import com.stoken.service.MemberLeaveReplyService;
import com.stoken.service.NoticeService;
import com.symbio.commons.Page;
import com.symbio.dao.hibernate.GenericDaoImpl;
import com.symbio.service.impl.AbstractServiceImpl;

@Service
public class MemberLeaveReplyServiceImpl extends AbstractServiceImpl<MemberLeaveReply, Long> implements MemberLeaveReplyService{
	
    @Autowired
	private MemberLeaveReplyDao memberLeaveReplyDao;
    
    @Autowired
    private MemberLeaveMessageDao memberLeaveMessageDao;

	@Override
	public GenericDaoImpl<MemberLeaveReply, Long> getDao() {
		return memberLeaveReplyDao;
	}
    
	@Override
	public MemberLeaveReply getMessageReply(String mlmId) {
	    
		return memberLeaveReplyDao.find("leaveTopic.id", mlmId);
	}

	@Override
	public void writeLeaveMessage(String reContext, long id) {
		
		MemberLeaveReply memberLeaveReply = new MemberLeaveReply();
		memberLeaveReply.setReplyContent(reContext);
		memberLeaveReply.setReplyTime(new Date());
		memberLeaveReplyDao.save(memberLeaveReply);
		MemberLeaveMessage mbLeaveMessage = memberLeaveMessageDao.find(id);		
		mbLeaveMessage.setIsReply(1);
		mbLeaveMessage.setLeaveReply(memberLeaveReply);
		memberLeaveMessageDao.update(mbLeaveMessage);
		
	}


}
